package com.esirong.whatime;

import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.util.Log;

import com.esirong.dao.DaoMaster;
import com.esirong.whatime.model.TaskDaoMasterImp;

/**
 * Created by esirong on 2015-04-16.
 */
public class Application extends android.app.Application {

    public static final int INIT_SUCCESS = -1;
    private static final String TAG = "Application";
    private static Application instance;
    private DaoMaster daoMaster;
    public static Application getInstance(){
        if(instance == null){
            instance = new Application();
        }
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    public void initData(Handler handler){
        Log.d(TAG,"initData");
        //TODO 初始化数据库
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "AWEEK.db",
                null);
        SQLiteDatabase db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        TaskDaoMasterImp.getInstance().init();
        handler.sendEmptyMessage(INIT_SUCCESS);
    }

    public DaoMaster getDaoMaster(){
        return daoMaster;
    }
}
